/**
 * @filename:CapitalTypeServiceImpl 2023-4-20
 * @project Wonder Java前后台分离框架  1.1.0
 * Copyright(c) 2022 Wonder Co. Ltd.
 * All right reserved.
 */
package com.wonder.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vtuzx.core.utils.VtuzxUtil;
import com.wonder.app.domain.MoldAndInspect;

import com.wonder.app.mapper.MoldAndInspectDao;

import com.wonder.app.request.MoldAndInspectRequest;

import com.wonder.app.service.MoldAndInspectService;

import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

/**
 * @Description:TODO(模具链类型服务实现)
 *
 * @version: 1.1.0
 * @author: Wonder
 *
 */
@Service

public class MoldAndInspectServiceImpl extends ServiceImpl<MoldAndInspectDao, MoldAndInspect> implements MoldAndInspectService {

    @Autowired
    private MoldAndInspectDao moldAndInspectDao;
    @Autowired
    private MoldAndInspectService moldAndInspectService;

    @Override
    public String validate(MoldAndInspect moldAndInspect, String type) {
        return "";
    }

    @Override
    public IPage<MoldAndInspect> selectList(MoldAndInspectRequest request, Page<MoldAndInspect> page) {
        LambdaQueryWrapper<MoldAndInspect> lambdaQueryWrapper = new LambdaQueryWrapper<>();

        if (null != request.getId()) {
            lambdaQueryWrapper.eq(MoldAndInspect::getId, request.getId());
        }


        lambdaQueryWrapper.orderByDesc(MoldAndInspect::getId);
        Page<MoldAndInspect> selectPage = this.baseMapper.selectPage(page, lambdaQueryWrapper);
        return selectPage;
    }


    /**
     * 创建关联表信息(添加模具链信息)
     * @param map
     * @return
     */
    @Override
    public boolean createAndInspect(String userName,Map<String,Object> map){
        MoldAndInspect moldAndInspect = new MoldAndInspect();
        moldAndInspect.setMoldId(VtuzxUtil.getLong(map,"moldId"));
        moldAndInspect.setCreateTime(new Date());
        moldAndInspect.setOrderTime(VtuzxUtil.getObject(map,"orderTime"));
        moldAndInspect.setOrderNo(VtuzxUtil.getString(map,"orderNo"));
        moldAndInspect.setCreateUserName(userName);
        moldAndInspect.setOrdertType(VtuzxUtil.getInt(map,"orderType"));
        return moldAndInspectService.saveOrUpdate(moldAndInspect);

    }
}
